<template>
  <div>
    <el-breadcrumb>
      <el-breadcrumb-item> <span class="headerSpan"></span>添加新品牌<el-button size="small" icon="el-icon-arrow-left" @click="$router.go(-1)">返回</el-button></el-breadcrumb-item>
    </el-breadcrumb>
    <div class="add">
      <div class="add_hed">添加新品牌</div>
      <!-- form表单区域 -->
      <el-form :model="addForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="品牌名称:" prop="name" label-width="130px">
          <el-input v-model="addForm.name"></el-input>
        </el-form-item>
        <el-form-item label="品牌首字母:" prop="letter" label-width="130px">
          <el-input v-model="addForm.letter"></el-input>
        </el-form-item>
        <el-form-item label="品牌LOGO:" prop="image" label-width="130px">
          <el-upload class="upload-demo" drag :action="addForm.name" :file-list="fileList" list-type="picture" :on-progress="handleProgress">
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            <div class="el-upload__tip" slot="tip">只能上传jpg/png格式文件，文件不能超过50kb</div>
          </el-upload>
        </el-form-item>
        <el-form-item label-width="130px">
          <el-button type="primary" @click="add()">提交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      addForm: {
        name: '',
        letter: '',
        image: ''
      },
      fileList: [],
      rules: {
        name: [
          { required: true, message: '请输入品牌名称', trigger: 'blur' },
          { min: 2, max: 5, message: '长度在 2 到 5 个字符', trigger: 'blur' }
        ],
        image: [{ required: true, message: '请添加品牌LOGO', trigger: 'change' }]
      }
    }
  },
  methods: {
    add() {
      this.$refs.ruleForm.validate(async valid => {
        if (!valid) {
          return
        }
        const { data: res } = await this.$http.post('/brand/add')
        console.log(res)
      })
    },
    handleProgress(event, file, fileList) {
      console.log(event, file, fileList)
      this.addForm.image = file
    }
  }
}
</script>
<style lang="less" scoped>
.add {
  position: relative;
  margin: 20px 40px 20px 20px;
  border: 1px solid #e6e6e6;
  .add_hed {
    width: 100%;
    height: 45px;
    padding-left: 20px;
    color: #666666;
    font-size: 12px;
    line-height: 45px;
    border-bottom: 1px solid #e6e6e6;
    background-color: #f3f3f3;
  }
  .el-form {
    position: absolute;
    top: 100px;
    left: 300px;
    .el-input {
      width: 250px;
    }
  }
}
</style>
